package megrez.keycloak.providers.mail;

import java.util.Locale;

import lombok.experimental.UtilityClass;
import megrez.keycloak.common.Consts;
import megrez.keycloak.common.MailMessage;
import megrez.keycloak.providers.mqtt.MqttUtils;

/**
 * 工具
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@UtilityClass
public class MailUtils {
    public String getMqttTopic(final String realmId) {
        String topic = Consts.MQTT_TOPIC_PREFIX_MAIL + "/" + realmId;
        return  MqttUtils.normalizeTopic(topic).toUpperCase();
    }

    public MailMessage buildMailMessage(Locale locale, String mail, String firstName, String lastName, String subject,
            String textBody, String htmlBody) {
        MailMessage rslt = new MailMessage();
        rslt.setLocale(locale);
        rslt.addMail(mail);
        rslt.setSubject(subject);
        rslt.addParam("firstName", firstName)
                .addParam("lastName", lastName)
                .addParam("textBody", textBody)
                .addParam("htmlBody", htmlBody);
        rslt.setTemplateCode(Consts.MAIL_TEMPLATE_CODE_KEYCLOAK);
        return rslt;
    }
}
